<template>
    <div id="manage">
        <div class="manage_top">
            <div class="form">
                <div style="margin: 15px 20px 0 20px">
                    <zy-select v-if="formConfig" :fromValue="queryForm" :formConfig="formConfig" @search="search" @resetForm="resetForm" :actions="actions"></zy-select>
                </div>
                <div style="height: 40px; display: flex; margin: 10px 20px 0 20px">
                    <div class="table_title">{{ table_title }}管理</div>
                    <div class="btns">
                        <el-button v-for="item in actions" :key="item.label" :icon="item.icon" @click="item.click()">{{ item.label }}</el-button>
                    </div>
                </div>
            </div>
        </div>
        <div class="manage_bottom">
            <div class="table">
                <div class="table_mask"></div>
                <zy-table :loading="loading" :tableData="tableData" :tableColumn="tableColumn" :pageSize="pagination.pageSize" :total="pagination.total" @changePage="changePage" @changeID="changeID"></zy-table>
            </div>
        </div>
        <zy-form ref="zyform" :dialog="dialog" @add="add" @set="edit"></zy-form>
        <menu-vue ref="menu1" />
        <List ref="list" />
    </div>
</template>
<script>
import { mapState } from 'vuex'
import { reportViewpdfApi } from '@/requset/api'
import List from './List.vue'
import { formConfig, config, column } from './formConfig.js'
import SearchManage from '@/components/basic/SearchManage.vue'
import { requestApi } from '@/requset/api'
import { deepClone } from '@/plugins/clone'
import menuVue from './menu.vue'
export default {
    extends: SearchManage,
    data() {
        return {
            table_title: '算法测试',
            url: 'algtest',
            model_groups: [],
            actions: [
                {
                    label: '添加',
                    icon: 'el-icon-folder-add',
                    click: () => {
                        this.handleAdd()
                    },
                    if: () => this.operate,
                },
            ],
            baseForm: {
                name: '',
                maker: '',
                models: null,
                topic: null,
            },
            queryForm: {
                name: '',
                topic: '',
                maker: '',
                page: 1,
                size: 20,
            },
            queryFormC: {
                name: '',
                maker: '',
                topic: '',
                page: 1,
                size: 20,
            },
        }
    },
    components: { menuVue, List },
    methods: {
        add(data) {
            requestApi('post', this.url + '/add', deepClone(data)).then((res) => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: '添加成功',
                    })
                    this.getlist()
                    this.$refs.zyform.closeDialog()
                }
            })
        },
        handel2(e) {
            this.$refs.menu1.doOpen(e)
        },
        searchBtn() {
            // let arr = this.queryForm.scope_id_list
            // if (arr.length != 0) this.queryForm.scope_id = arr[arr.length - 1]
            this.getlist()
        },
        getModel_group() {
            return requestApi('post', 'model_group/getlist', { size: 99999, page: 1 }).then((res) => {
                if (res.data.code == 0) {
                    this.model_groups = res.data.data
                }
            })
        },
        reportViewpdf(filename) {
            reportViewpdfApi(filename)
        },
    },
    computed: {
        ...mapState('backstage', ['backstageData', 'deviceType']),
        tags() {
            if (this.pagination.total !== undefined) {
                return [{ title: '总数', num: this.pagination.total }, null, { title: '编辑中', num: this.stat.editing }, { title: '已完成', num: this.stat.completed }]
            } else return []
        },
    },
    created() {
        this.searchBtn()
        formConfig[1].options = this.backstageData
        this.formConfig = formConfig
        this.getModel_group().then(() => (config[2].options = this.model_groups))

        this.dialog.config = config
        column[column.length - 1].buttons = [
            {
                text: '详情',
                click: (val) => this.$refs.list.doOpen(val),
                icon: 'el-icon-s-comment',
            },
            {
                text: '编辑',
                click: (val) => this.handleEdit(val),
                icon: 'el-icon-edit',
            },
            {
                text: '处理',
                click: (val) => this.handel2(val),
                icon: 'el-icon-edit-outline',
            },
            {
                text: '删除',
                click: (val) => this.delete(val),
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        this.tableColumn = column
    },
}
</script>
